#include "set_clock.h"

void Init_Clock_32MHz(void)
{
	OSC.CTRL = OSC_RC32MEN_bm; /* start 32MHz RC oscillator */
	while (!(OSC.STATUS & OSC_RC32MRDY_bm)); /* wait for ready */
	CCP = CCP_IOREG_gc; /* allow changing CLK.CTRL */
	CLK.CTRL = CLK_SCLKSEL_RC32M_gc; /* system clock is internal 32MHz RC */
	
	//Activate DFLL in ATXMEGA
	OSC.DFLLCTRL = 0x00;
	DFLLRC32M_COMP0 = 0x39;
	DFLLRC32M_COMP1 = 0x12;
	DFLLRC2M_COMP2 = 0x7A;
	DFLLRC32M_CTRL = DFLL_ENABLE_bm;
}